﻿using M_Quality.API.Application.Command.QualitygroupCommand;
using M_Quality.API.Application.Command.QualityinspectionCommand;
using M_Quality.Repository.Impl;
using M_Quality.Repository.Interface;
using MediatR;

namespace M_Quality.API.Application.CommandHandler.QualityinspectionHandler
{
    public class QualityinspectionDeleteCommandHandler : IRequestHandler<QualityinspectionDeleteCommand, int>
    {

        protected readonly IQualityinspectionRepository qualityinspectionRepository;

        public QualityinspectionDeleteCommandHandler(IQualityinspectionRepository qualityinspectionRepository)
        {
            this.qualityinspectionRepository = qualityinspectionRepository;
        }

        public async Task<int> Handle(QualityinspectionDeleteCommand request, CancellationToken cancellationToken)
        {
            var id =  request.QualityinspectionId;
            foreach (var item in id)
            {
                var res = await qualityinspectionRepository.GetModelAsync(item);
                res.IsDeleted = true;
             
                await qualityinspectionRepository.UpdateAsync(res);
            }
            return 1;
        }
    }
}
